<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<button id="but">百度</button>
		
		<script>			
			
			//数字取整，四舍五入，随机数
			/*var r = Math.ceil(10);   //向上取整
			var r = Math.floor(10);  //向下取整
			var r = Math.round(1.56789) //2 四舍五入
			var r = Math.random();   //取一个0~1之间的一个随机数
			var r = Math.floor(Math.random()*10); //0~9之间的一个随机整数
			var r = Math.floor(Math.random()*10) + 1; //1~10之间的一个随机整数
			console.log(r);*/
			
			//遍历数组
			/*var arr = [2, 8, 7, 3, 8, 6, 2];
			var len = arr.length, i;
			for(var i = 0; i<len; i++) {
				document.write(arr[i]);
			};*/
			
			//数组排序方法
			/*var arr1 = [2, 8, 7, 3, 8, 6, 2];
			arr1.sort(function( a , b ) {
				return a-b;				
			});
			console.log(arr1);*/
			
			//非超级链接打开新窗口
			/*var but = document.getElementById('but');
			but.onclick = function(){
				//window.open('http://www.baidu.com');//在新窗口打开
				location.href = 'http://www.baidu.com';//在原窗口打开
			};*/
			
			var arr2 = [2, 8, 7, 3, 8, 6, 2];
			function uniq(arr2) {
				var obj = {}, i=0, len = arr.length, key;
				for (; i<len; i++) {
					obj[arr[i]] = arr[i];
				}
				arr.length = 0;
				for (key in obj) {
					arr.push(obj[key]);
				}
				return arr;
			};
			var r = uniq(arr1);
			console.log(r);			
	</body>
</html>
